﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Repositories.Internal;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Core.SimpleTemp.Entitys.Sys;

namespace Core.SimpleTemp.Application.SysApp.SysFactoryApp
{
    [AutoDi()]
    public class SysFactoryService
    {
        CoreDBContext _coreDBContext;
        public SysFactoryService(CoreDBContext coreDBContext)
        {
            _coreDBContext = coreDBContext;
        }
        public async System.Threading.Tasks.Task<SysFactory> GetFactoryAsync(Guid id)
        {
            return await _coreDBContext.SysFactory.SingleAsync(a => a.Id == id);
        }

        public bool IsDayShift(SysFactory factory, DateTime dateTime)
        {
            var hour = dateTime.Hour;
            var isDayShift = hour >= factory.DayShiftStart && hour <= factory.DayShiftEnd;
            return isDayShift;
        }
        public async System.Threading.Tasks.Task<bool> isDayShiftAsync(Guid factoryId, DateTime dateTime)
        {
            var factory = await this.GetFactoryAsync(factoryId);
            var isDayShift = IsDayShift(factory, dateTime);
            return isDayShift;
        }
    }
}
